<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Register</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="../style/css/demo.css" rel="stylesheet" type="text/css" />

    <style type="text/css">
    body
    {
        width:100%;height:100%;margin:0;overflow:hidden;
    }
    </style>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    
</head>
<body >   
<div id="loginWindow" class="mini-window" title="用户注册" style="width:350px;height:200px;" 
   showModal="true" showCloseButton="false"
    >

    <div id="loginForm" style="padding:15px;padding-top:10px;">
        <table >
            <tr>
                <td style="width:60px;"><label for="username$text">帐号：</label></td>
                <td>
                    <input id="username" name="username" onvalidation="onUserNameValidation" class="mini-textbox" required="true" style="width:150px;" requiredErrorText="帐号不能为空"/>
                </td>
                <td id="username_error" class="errorText"></td>    
            </tr>
            <tr>
                <td style="width:60px;"><label for="pwd$text">密码：</label></td>
                <td>
                    <input id="password" name="pwd" onvalidation="onPwdValidation" class="mini-password"  required="true" style="width:150px;"/> 
                </td>
                <td id="pwd_error" class="errorText"></td>
            </tr> 
            <tr>
                <td style="width:60px;"><label for="pwd$text">重复密码：</label></td>
                <td>
                    <input id="re_pwd" name="re_pwd" class="mini-password"  required="true" style="width:150px;" onenter="onRegisterClick"/> 
                </td>
                <td id="repwd_error" class="errorText"></td>
            </tr>            
            <tr>
                <td></td>
                <td style="padding-top:5px;">
                    <a onclick="onRegisterClick" class="mini-button" style="width:60px;">注册</a>
                    <a onclick="onResetClick" class="mini-button" style="width:60px;">重置</a>
                </td>
            </tr>
        </table>
    </div>

</div>
    <script type="text/javascript">
        mini.parse();

        var loginWindow = mini.get("loginWindow");
        loginWindow.show();

        function onRegisterClick(e) {
            var form = new mini.Form("#loginWindow");//这里是得到注册表单
			var o = form.getData(); //这里得到了表单里的数据，我们弹窗看看
			
            form.validate();
            if (form.isValid() == false) return;
			 var json = mini.encode([o]);
			 alert(json);//return ;//是这里我直接return了。就没往下执行
            $.ajax({//这里是jquery的ajax的写法
                url: "../dataService/userService.jsp?method=register",//url是把数据发到哪个url，由谁处理
				type: 'post',//这里是发送的方式，可以使post或者get，一般都用post
                data: { data: json },//这里很明显就是要发送的数据了
                cache: false,
                success: function (text) {//这里是发送成功了，然后由结果返回回来了，这个结果是后台返回的字符串或者对象啥的text
                     loginWindow.hide();
            		mini.loading("注册成功，马上转到登陆页面", text);
           			 setTimeout(function () {
                		window.location = "login.html";
            		}, 1500);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
           
        }
        function onResetClick(e) {
            var form = new mini.Form("#loginWindow");
            form.clear();
        }
        /////////////////////////////////////
        function isEmail(s) {
            if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
                return true;
            else
                return false;
        }
        function onUserNameValidation(e) {
            if (e.isValid) {
                if (isEmail(e.value) == false) {
                    e.errorText = "必须输入邮件地址";
                    document.getElementById("username_error").innerHTML=e.errorText;
                    e.isValid = false;
                }else{
                 document.getElementById("username_error").innerHTML="";
                }
            }
        }
        function onPwdValidation(e) {
            if (e.isValid) {
                if (e.value.length < 5) {
                    e.errorText = "密码不能少于5个字符";
                    document.getElementById("pwd_error").innerHTML=e.errorText;
                    e.isValid = false;
                }else{
                 document.getElementById("pwd_error").innerHTML="";
                }
            }
        }
        function onRePwdValidation(e) {
        var maintenance_men=document.getElementById("password").value; 
		alert(maintenance_men); 
            if (e.value!=document.getElementById("pwd").value) {
                    e.errorText = "两次输入的密码不一致";
                    document.getElementById("repwd_error").innerHTML=e.errorText;
                    e.isValid = false;
            }else{
                 document.getElementById("repwd_error").innerHTML="";
                }
        }
    </script>
</body>
</html>